package com.googlecode.loframework.view.components.quizzes
{
	import com.googlecode.loframework.core.NotificationNames;
	import com.googlecode.loframework.view.IComponent;
	
	import flash.events.Event;
	
	import mx.core.UIComponent;

	/**
	 * Ties in the PersonalityQuestion component with the PureMVC Framework. 
	 * @author ~martin
	 * 
	 */
	public class PersonalityQuestionMediator extends QuizMediator
	{
		
		/**
		 * Identifier. This is made unique by the addition of a number at its end.
		 * PersonalityQuestion components have to be registered dynamically. 
		 */
		private var _name:String = "PersonalityQuestionMediator";
		
		/**
		 * Constructor 
		 * @param viewComponent
		 * 
		 */
		public function PersonalityQuestionMediator(viewComponent:IComponent)
		{
			super(_name, viewComponent);
		}
		
		/**
		 * Triggered when the mediator is added to the PureMVC framework.
		 * 
		 */
		override public function onRegister():void
		{
			super.onRegister();
			
			// add event listener to listen for radio button change events
			viewRef.addEventListener(Choice.CHOICE_SELECTED, onRadioButton);	
		}
		
		/**
		 * Responds to a user clicking on a component of the type IChoice. 
		 * @param evt
		 * 
		 */
		protected function onRadioButton(evt:Event):void
		{
			sendNotification(NotificationNames.COMPONENT_PERSONALITY_QUESTION_CHANGED, evt.target);
		}
		
		/**
		 * Triggered when the mediator is removed from the PureMVC framework. 
		 * 
		 */
		override public function onRemove():void
		{
			super.onRemove();
			
			viewRef.removeEventListener(Choice.CHOICE_SELECTED, onRadioButton);

		}
		
		protected function get viewRef():UIComponent
		{
			return viewComponent as UIComponent;
		}
	}
}